#include <vulkan/vulkan.h>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>

int main(int argc, char** argv)
{
    if (!glfwInit())
    {
        printf("Failed to initialize GLFW.\n");
        return 1;
    }

    if (!glfwVulkanSupported())
    {
        printf("Vulkan not supported.\n");
        return 1;
    }

    uint32_t glfwExtCount = 0;
    const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtCount);
    printf("GLFW initialized. It requires the following extensions:\n");
    for (uint32_t i = 0; i < glfwExtCount; i++)
        printf("    %s\n", glfwExtensions[i]);

    VkApplicationInfo appInfo
    {
        VK_STRUCTURE_TYPE_APPLICATION_INFO,
        nullptr,
        "c01_instance",
        VK_MAKE_VERSION(1, 0, 0),
        "VulkanClass",
        VK_MAKE_VERSION(1, 0, 0),
        VK_API_VERSION_1_3,
    };

    VkInstanceCreateInfo instanceInfo
    {
        VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
        nullptr, 0,
        &appInfo,
        0, nullptr,
        glfwExtCount, glfwExtensions
    };

    //PFN_vkCreateInstance vkCreateInstance = (PFN_vkCreateInstance)
    //    glfwGetInstanceProcAddress(NULL, "vkCreateInstance");
    VkInstance instance = nullptr;
    VkResult result = vkCreateInstance(&instanceInfo, nullptr, &instance);
    if (result != VK_SUCCESS)
    {
        printf("Vulkan instance creation failed: %d\n", result);
        return 1;
    }

    printf("Vulkan instance created: %p\n", instance);
    // TODO

    if (instance != nullptr) vkDestroyInstance(instance, nullptr);
    glfwTerminate();
    return 0;
}